//
//  HXNutritionalEffectVC.m
//  ZCooking
//
//  Created by 韩旭 on 16/9/16.
//  Copyright © 2016年 HX_. All rights reserved.
//

#import "HXNutritionalEffectVC.h"
#import "HX_Macro.h"
#import "HXNutritionTCell.h"
@interface HXNutritionalEffectVC ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) NSArray *string;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIImageView *imgHeader;
@end

@implementation HXNutritionalEffectVC

- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 250) style:0];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [self.view addSubview:_tableView];
        [_tableView registerNib:[UINib nibWithNibName:@"HXNutritionTCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"HXNutritionTCell"];
        _tableView.tableHeaderView = self.imgHeader;
        _tableView.separatorStyle = 0;
    }
    return _tableView;
}
- (void)creatHeaderView {
    self.imgHeader = [[UIImageView alloc] init];
    [self.imgHeader sd_setImageWithURL:[NSURL URLWithString:self.imgString]];
    _imgHeader.HX_x = 0;
    _imgHeader.HX_y = 0;
    self.imgHeader.HX_height = 150;
    self.imgHeader.HX_width = SCREEN_WIDTH;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.string.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HXNutritionTCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HXNutritionTCell"];
    cell.detailLabel.text = self.string[indexPath.row];
    cell.backgroundColor = [UIColor whiteColor];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    CGFloat height = [SelfSizeTools selfSizeHeightWithString:self.string[indexPath.row] Width:SCREEN_WIDTH Font:[UIFont systemFontOfSize:15]];
    return height;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.string = [self.purchaseDetail componentsSeparatedByString:@"\r\n"];
    [self creatHeaderView];
    [self tableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
